public class Solution extends GuessGame {
    public int guessNumber(int n) {

        return binSearch(1, n);
    }

    public int binSearch(int left, int right) {
        int mid = left + (right - left) / 2;
        int flag = guess(mid);
        if (flag == 0) return mid;
        else if (flag < 0) return binSearch(left, mid - 1);
        else return binSearch(mid + 1, right);
    }
}
